package com.ruoyi.generator.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.generator.common.query.Query;
import com.ruoyi.generator.domain.BaseClassEntity;
import com.ruoyi.generator.service.BaseClassService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 基类管理
 */
@RestController
@RequestMapping("gen/baseclass")
@AllArgsConstructor
public class BaseClassController extends BaseController {
    private final BaseClassService baseClassService;

    @GetMapping("page")
    public TableDataInfo page(Query query) {
        return getDataTable(baseClassService.page(query));
    }

    @GetMapping("list")
    public R<List<BaseClassEntity>> list() {
        List<BaseClassEntity> list = baseClassService.getList();

        return R.ok(list);
    }

    @GetMapping("{id}")
    public R<BaseClassEntity> get(@PathVariable("id") Long id) {
        BaseClassEntity data = baseClassService.getById(id);

        return R.ok(data);
    }

    @PostMapping
    public R<String> save(@RequestBody BaseClassEntity entity) {
        baseClassService.save(entity);

        return R.ok();
    }

    @PutMapping
    public R<String> update(@RequestBody BaseClassEntity entity) {
        baseClassService.updateById(entity);

        return R.ok();
    }

    @DeleteMapping
    public R<String> delete(@RequestBody Long[] ids) {
        baseClassService.removeBatchByIds(Arrays.asList(ids));

        return R.ok();
    }
}